package com.pkx.guide;

import java.io.*;
import java.net.*;
public class TCPClient {
   public static void main(String[] args) {
       try {
           // 创建TCP客户端并连接到服务器
           String serverAddress = "192.168.0.115";
           int serverPort = 5227;
           Socket clientSocket = new Socket(serverAddress, serverPort);
           // 创建输入流和输出流
           InputStream inputStream = clientSocket.getInputStream();
           OutputStream outputStream = clientSocket.getOutputStream();
           // 发送数据给服务器
           String message = "000000";
           outputStream.write(message.getBytes());
           // 读取服务器响应的数据
           byte[] buffer = new byte[1024];
           int bytesRead = inputStream.read(buffer);
           String receivedMessage = new String(buffer, 0, bytesRead);
           System.out.println("收到服务器响应：" + receivedMessage);
           // 关闭连接
           clientSocket.close();
       } catch (Exception e) {
           e.printStackTrace();
       }
   }
}